<%@ page contentType="text/html; charset=UTF-8"%>
<%@ include file="/WEB-INF/view/system/common/headLogin.jsp"%>
<script type="text/javascript" src="asserts/system/js/sysUser/sysUser.js"></script>

<body>

	<form id="form1" name="form1" method="post">
		<input type="hidden" name="userIds" value="${userIds}">
		<input type="hidden" id="setGroupId" name="groupId">
		<!-- <input type="hidden" id="setGroupName" name="setGroupName"> -->
		<table id="userListDataShow">
		</table>
		<br />
		<table id="groupTreegrid"></table>
		<div style="text-align:center;">
			<br />
			<a class="easyui-linkbutton  myLink" iconCls="icon-ok"
				onclick="submitForm()">设置</a> &nbsp;
			<a  class="easyui-linkbutton  myLink" iconCls="icon-undo"
				onclick="closeForm()">关闭</a>
		</div>
	</form>
</body>

<script type="text/javascript" src="asserts/plugins/easyui/treegrid-dnd.js"></script>
<script type="text/javascript">

$(document).ready(function() {
	setTreeGridList();
	setUserListDataGridList();
});

function setUserListDataGridList() {
$('#userListDataShow').datagrid({
		data:${userGroupSetUserList},
		title:"待更换分组的用户列表",
		fitColumns:true,nowrap:false,rownumbers:true,showFooter:false,striped:true,singleSelect:false,
		idField:'id',
		columns:[[{field:'id',width:10,hidden:true,sortable:false}
			,{field:'username',title:"用户名",width:15}
			,{field:'code',title:"工号",width:10,sortable:false}
			,{field:'name',title:"姓名",width:20,sortable:false}
			,{field:'groupname',title:"所属分组",width:15,sortable:false}
			,{field:'userstate',title:"状态",width:20,sortable:false,formatter:function(val){return val==0?'正常':(val==1?'已删':'已禁用');}}
		]]
	});
}
var groupTypeListJSON = eval('(${groupTypeListJSON})');
function setTreeGridList(){
	$('#groupTreegrid').treegrid({
				title:'用户分组树',
				nowrap:false,
				fitColumns:true,
				rownumbers:true,singleSelect :true,
				fixed:true,
				animate:true,
				url:'usergroup/getGroups.action',
				idField:'id',
				treeField:'name',
				frozenColumns:[[{title:'名称',field:'name',width:'40%',
					formatter:function(value,rowData){
							if(rowData.type==2)	return '<input name="menuCheckBox" type="radio" na="'+rowData.name+'" id="menuCB' + rowData.id + '" value="' + rowData.id + '" /><span style="color:blue">'+value+'</span>';
						return '<input name="menuCheckBox" type="radio" na="'+rowData.name+'" id="menuCB' + rowData.id + '" value="' + rowData.id + '" /><span style="color:red">'+value+'</span>';}}
				]]
				,columns:[[{field:'code',title:'编码',width:'10%'}
					,{field:'type',title:'类型',width:'15%',formatter:function(val){
						for(var i = 0; i < groupTypeListJSON.length;i++){
							if(groupTypeListJSON[i].value == val){
								return groupTypeListJSON[i].name;
							}
						}
						
						return val;}}
					,{field:'descr',title:'分组描述',width:'30%'}
				]]
				,tools: [{iconCls: 'icon-reload',handler: function(){$("#groupTreegrid").treegrid('reload');}}]
				,onSelect:function(row){
					if(!document.getElementById("menuCB"+row.id).checked){
						document.getElementById("menuCB"+row.id).checked=true;
					}
				}
				,onUnselect:function(row){
					if(document.getElementById("menuCB"+row.id).checked){
						document.getElementById("menuCB"+row.id).checked=false;
					}
				}
	});
}

function submitForm(){
	var selectedId = $("input[name='menuCheckBox']:checked").val();
	if(selectedId==undefined) {
		$.messager.alert("错误信息","请选择将所选用户更换到哪个分组", 'error');
		return;
	}
	var selectedName = $("input[name='menuCheckBox']:checked").attr('na');
	$("#setGroupId").val(selectedId);
	$("#setGroupName").val(selectedName);
	var param = $('#form1').serializeJson(true);
	//提交后台处理  
	//$.post("doUserGroupSet.action" + param, callback);
	$.axs("user/doUserGroupSet.action", param, function(data){
		if(data.status == 1){
			$.messager.alert("提示信息", data.msg, 'info', function() {
				closeParentTTTab();
			});
		}else{
			$.messager.alert("错误信息", data.msg, 'error');
		}
	});
}

function closeForm(){
	closeParentTTTab();
}




</script>
</html>
